using System;
using ConsentManagementProviderLib;
using ConsentManagementProviderLib.EventHandlerInterface;
using UnityEngine;
using UnityEngine.EventSystems;

namespace Voodoo.Sauce.Privacy.Sourcepoint
{
	public class SourcepointBehaviour : MonoBehaviour, IOnConsentUIReady, IConsentEventHandler, IEventSystemHandler, IOnConsentAction, IOnConsentError, IOnConsentUIFinished, IOnConsentReady
	{
		public class SourcepointBehaviourParameters
		{
			public Action onConsentUIReady;

			public Action<CONSENT_ACTION_TYPE> onConsentAction;

			public Action<Exception> onConsentError;

			public Action onConsentUIFinished;

			public Action<SpConsents> onConsentReady;
		}

		private Action _onConsentUIReady;

		private Action<CONSENT_ACTION_TYPE> _onConsentAction;

		private Action<Exception> _onConsentError;

		private Action _onConsentUIFinished;

		private Action<SpConsents> _onConsentReady;

		public void Initialize(SourcepointBehaviourParameters parameters)
		{
			UnityEngine.Object.DontDestroyOnLoad(this);
			_onConsentUIReady = parameters.onConsentUIReady;
			_onConsentAction = parameters.onConsentAction;
			_onConsentError = parameters.onConsentError;
			_onConsentUIFinished = parameters.onConsentUIFinished;
			_onConsentReady = parameters.onConsentReady;
			ConsentMessenger.AddListener<IOnConsentUIReady>(base.gameObject);
			ConsentMessenger.AddListener<IOnConsentAction>(base.gameObject);
			ConsentMessenger.AddListener<IOnConsentError>(base.gameObject);
			ConsentMessenger.AddListener<IOnConsentUIFinished>(base.gameObject);
			ConsentMessenger.AddListener<IOnConsentReady>(base.gameObject);
		}

		public void OnConsentUIReady()
		{
			_onConsentUIReady?.Invoke();
		}

		public void OnConsentAction(CONSENT_ACTION_TYPE action)
		{
			_onConsentAction?.Invoke(action);
		}

		public void OnConsentError(Exception exception)
		{
			_onConsentError?.Invoke(exception);
		}

		public void OnConsentUIFinished()
		{
			_onConsentUIFinished?.Invoke();
		}

		public void OnConsentReady(SpConsents consents)
		{
			_onConsentReady?.Invoke(consents);
		}
	}
}
